//
//  BaseNavBar.swift
//  jingxin
//
//  Created by Yuki on 2020/8/5.
//  Copyright © 2020 Zl. All rights reserved.
//  自定义导航栏

import UIKit

class BaseNavBar: BaseView {
    
    /**  返回按钮  **/
    lazy var leftButton = UIButton();
    /**  标题  **/
    lazy var titleLb = UILabel();
    /**  底部横线  **/
    lazy var lineView = UIView();
    

    public override init(frame: CGRect) {
        super.init(frame: frame);
        /**  固定导航栏的size  **/
        self.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 44+UIApplication.shared.statusBarFrame.height);
        self.backgroundColor = UIColor.init(red: 243.0, green: 243.0, blue: 243.0, alpha: 1);
        /**  创建界面  **/
        buildUI();
    }
    
    /**  初始化  **/
    required init?(coder: NSCoder) {
        super.init(coder: coder);
        /**  创建界面  **/
        buildUI();
    }
    
    
    /**  创建界面  **/
    func buildUI(){
        /**  返回按钮  **/
        leftButton = UIButton.init(type: .custom);
        leftButton.frame = CGRect(x: 15, y: UIApplication.shared.statusBarFrame.height, width: 40, height: 40);
        leftButton.setImage(UIImage(named: "nav_back_black"), for: .normal);
        self.addSubview(leftButton);
    
        /**  标题  **/
        titleLb = UILabel.init();
        titleLb.font = UIFont.systemFont(ofSize: 17);
        titleLb.textAlignment = .center;
        self.addSubview(titleLb);
        titleLb.frame = CGRect(x: 65, y: UIApplication.shared.statusBarFrame.height, width: UIScreen.main.bounds.size.width - 130, height: 40);
        
        /**  底部横线  **/
        lineView = UIView.init();
        lineView.backgroundColor = UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.5);
        self.addSubview(lineView);
        lineView.frame = CGRect(x: 0, y: 43+UIApplication.shared.statusBarFrame.height, width: UIScreen.main.bounds.size.width, height: 1);
        
    }
    
    /**  是否显示横线  **/
    public var showLine: Bool! {
        didSet{
            lineView.isHidden = !showLine;
        }
    }
}
